<template>
    <div  class="inspectionOrder-container">
        <!-- 查询表单 -->
        <el-form :inline="true">
            <el-form-item>
                <el-autocomplete
                    v-model="searchObj.fiamid"
                    :trigger-on-focus="false"
                    class="inline-input"
                    placeholder="质检单号"
                    value-key="fiamid" />
            </el-form-item>
            <el-form-item>
                <el-autocomplete
                v-model="searchObj.fename"
                :trigger-on-focus="false"
                class="inline-input"
                placeholder="质检员"
                value-key="fename" />
            </el-form-item>
            <el-form-item>
                <el-select v-model="searchObj.fiamstatus" clearable placeholder="质检状态">
                    <el-option
                    v-for="item in status"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-date-picker
                v-model="searchObj.searchStartDate"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-date-picker
                v-model="searchObj.searchEndDate"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="-">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="fetchData()">查询</el-button>
                <el-button type="default" @click="resetData()">清空</el-button>
            </el-form-item>
        </el-form>
        
        <el-button type="primary" @click.native="vueCreate">创建质检单</el-button>
        <el-button type="primary" @click.native="vueCreate">导入Excel</el-button>
        <el-button type="primary" @click.native="vueCreate">导出Excel</el-button>
        <inspectioninfo v-if="dialogFormVisible" :dialogFormVisible="dialogFormVisible"  :updateOrCreate="updateOrCreate" :editInspectionOrder="editInspectionOrder" 
         @closepop="closepop" />
        <!-- 表单部分 -->
        <el-table
            :data="inspectionOrderList"
            style="width: 100%"
        >
            <el-table-column
                prop="fiamid"
                label="质检单号"
                width="130"
                sortable
                />
            <el-table-column
                prop="fpmid"
                label="采购单号"
                width="100"
                sortable
                />
            <el-table-column
                prop="fpamid"
                label="到货单号"
                width="100"
                sortable
                />
            <el-table-column
                prop="fename"
                label="质检员"
                width="150"
                sortable
                />
            <el-table-column
                prop="fpname"
                label="供应商"
                width="100"
                sortable
                />
            <el-table-column
                prop="fwhname"
                label="到货仓库"
                width="200"
                sortable
                />
            <el-table-column
                prop="fiamdate"
                label="质检日期"
                width="100"
                :formatter="dateFormat"
                sortable
                />
            <el-table-column
                prop="fiammemo"
                label="备注"
                width="200"
                sortable
                />
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button type="primary" size="big" @click="vueDelete(scope.row.fiamid)">删除</el-button>
                    <el-button type="primary" size="big"  @click="vueEdit(scope.row)">编辑</el-button>
                    <el-button type="primary" size="big"  @click="vueConfirm(scope.row.fiamid)">确认</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[10, 50, 100, 200]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="200" />
    </div>
</template>
<script>
import moment from 'moment'
import { getPurchaseArrivalOrderList, deletePurchaseArrivalOrder } from '@/api/arrivalOrder'
import { getInspectionOrderList, deleteInspectionOrder,confirmInspectionOrder } from '@/api/inspectionOrder'
import inspectioninfo from '@/views/warehouse/inspection/components/InspectionInfo'


export default {
    components: {
        inspectioninfo
    },
    data () {
        return {
            inspectionOrderList: {},
            searchObj: {},
            dialogFormVisible: false,
            /*true 代表更新，false代表创建*/
            updateOrCreate: false,
            editInspectionOrder: {},
            status: {}
            
        }
    },
    created() {
        this.fetchData()
    },
    methods: {
        // 事件格式化 利用momeent 模块 npm install moment
        dateFormat: function(row,column) {
            var date = row[column.property]
            if (date == undefined) {
                return ""
            }
            return moment(date).format("YYYY-MM-DD")
        },
        vueCreate() {
            this.dialogFormVisible=true
            this.updateOrCreate=false
        },
        vueEdit(row) {
            this.dialogFormVisible=true
            this.updateOrCreate=true
            this.editInspectionOrder=row
        },
        vueReset() {
            this.dialogFormVisible=false
            this.updateOrCreate=false
            this.editInspectionOrder={}
        },
        vueConfirm(fiamid){
            this.$confirm('是否确认到货，确认到货后不能再进行更改？','提示',{
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                confirmInspectionOrder(fiamid).then(response => {
                    this.fetchData()
                    this.$message({
                        type: 'success',
                        message: '确认状态成功'
                    })
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消确认状态'
                })
            })
        },
        vueDelete(fiamid) {
            this.$confirm('此操作将永久删除，受否继续？','提示',{
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                deletePurchaseArrivalOrder(fiamid).then(response => {
                    this.fetchData()
                    this.$message({
                        type: 'success',
                        message: '删除成功'
                    })
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                })
            })
        },
        fetchData() {
            getInspectionOrderList(this.searchObj).then(response => {
                this.inspectionOrderList = response.data.inspectionOrderVoList
            })
        },
        resetData() {
            this.searchObj = {}
        }
    }

}
</script>
<style lang="scss" scoped>
    .inspectionOrder-container {
      margin: 10px 50px 0;
      overflow: hidden;
    }
</style>